const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('doctor_medicine_lib', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    medicine_lib_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'medicine_lib',
        key: 'id'
      }
    },
    out_time: {
      type: DataTypes.DATE,
      allowNull: false
    },
    amount: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    out_amount: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false
    },
    conservator: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'user',
        key: 'id'
      }
    },
    doctor: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'user',
        key: 'id'
      }
    },
    memo: {
      type: DataTypes.TEXT,
      allowNull: true
    }
  }, {
    sequelize,
    tableName: 'doctor_medicine_lib',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "FK_doctor_ medicine _lib_id",
        using: "BTREE",
        fields: [
          { name: "medicine_lib_id" },
        ]
      },
      {
        name: "FK_doctor_ medicine _doctor",
        using: "BTREE",
        fields: [
          { name: "doctor" },
        ]
      },
      {
        name: "FK_doctor_ medicine _conservator",
        using: "BTREE",
        fields: [
          { name: "conservator" },
        ]
      },
    ]
  });
};
